<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		$('#example').dataTable( {
			"sScrollY": "800px",
			"bPaginate": false,
			"bScrollCollapse": true
		} );
	});
</script>

<script type="text/javascript">
	$(document).ready(function() {
			
	
			 $('#penerimaan_kas').submit(function() {
				var varbalance=document.getElementById('txt_balance').value;
			 
				if (varbalance!='0'){
					alert("Not Balance");
					return false;		
				}else{
				 
					$.ajax({
						type: 'POST',
						url: "<?=base_url().'index.php/penerimaan_kas/view_posting_penerimaan_kas/'?>",
						data: $('#penerimaan_kas').serialize(),
						success: function(data) {
							$.fancybox(data, {
								'width' : 840,
								'height': 900
							  });
						}
					});
					return false;		
				}
				
			}); 
		
		$("#getakun").fancybox(
			{
			'width' : 900, 'height' : 900
			});
	});
	
	function set_detail(){		
		if(document.getElementById('detail_akunid').value == ''){

			alert('Isi nama barang terlebih dahulu.');

		}else{

			$.ajax({

				type: 'POST',

				url: '<?=base_url().'asset/admin/js/ajax_penerimaan_kas.php?command=add_1'?>',

				data: $('#penerimaan_kas').serialize(),

				success: function(data) {

					$('#detail').html(data);

				}

			});

			

			document.getElementById('detail_akunid').value = '';	
			document.getElementById('detail_nakun').value = '';
			document.getElementById('detail_jumlah').value = '';
			document.getElementById('detail_count').value = '';

		}

	}
	
	function save_data(){
		var isi = document.getElementById('detail').innerHTML;
		if( isi == false){
			document.getElementById('alert_yanto').innerHTML = '<ul class="message error grid_12"><li>List data barang tidak boleh kosong</li><li class="close-bt"></li></ul><br>';

			alert('kosong');

			$('html, body').stop().animate({

				scrollTop: 0 //$($anchor.attr('href')).offset().top

			}, 700, 'easeInOutExpo');

		}else{

			document.getElementById('alert_yanto').innerHTML = '';
			alert('berisi');
			document.forms["penerimaan_kas"].submit();
		}

		

	}
	
	
	function remove_detail(id){

		$.ajax({

			type: 'POST',

			url: '<?=base_url().'asset/admin/js/ajax_penerimaan_kas.php?command=remove&id='?>'+id,

			data: $('#penerimaan_kas').serialize(),

			success: function(data) {

				$('#detail').html(data);

			}

		});
	}
	
	function batal(){
		document.location.href = '<?=base_url().'index.php/penerimaan_kas'?>';
	}
	
	function get_total_kas(){
		var getselect=document.getElementById('kd_kas').value;
		load("penerimaan_kas/get_kas/" + getselect ,"jumlah_kredit");	
		
	}
	
</script>

<script type="text/javascript">


			var newTotal=0;
			var newTotal_k=0;
			var counter = 0;
			var cancel_b = 0;
		function reset_txt(){
		
			document.getElementById('jumlah_pengeluaran').value=0;				
			document.getElementById('jumlah_pemasukan').value=0;				
		}
		$(document).ready(function(){
			$("#getakun0").fancybox({
				'width'         : 970,
				'max-height'    : 900,
				'autoDimensions': false,
				'autoScale'     : false,
				'transitionIn'  : 'elastic',
				'transitionOut' : 'elastic',
			});


            $('#addInputs').click(function(event){
                    event.preventDefault();
                    addInputEl() ;
            });
			
			$('#removeBtn').click(function(event){
                    event.preventDefault();
                    removeInputElm() ;
            });
            
			change_radio();
			reset_txt();
			
			
        });
		
		function addInputEl(){
			var akunidlastrow=document.getElementById('akunid' + counter).value;
			if (akunidlastrow!= 0 ){
				
				counter = counter+1;
				var val_radio = "pemasukan";
				inCon = document.getElementById('inputList');
				newP = document.createElement('p');
				
				newInput = document.createElement('input');
				newInput2 = document.createElement('input');
				newInput3 = document.createElement('a');;
				newInput4 = document.createElement('input');
				newInput6 = document.createElement('input');
				newInput5 = document.createElement('input');
				newInput_anggaran = document.createElement('input');
				newInput_parent = document.createElement('input');
				newInput_idanggaran = document.createElement('input');
				
				newInput_tr = document.createElement('tr');
				newInput_tr.setAttribute('align','center');
				newInput_tr.setAttribute('class','alternate-row');
				newInput_td = document.createElement('td');
				newInput_td2 = document.createElement('td');
				newInput_td3 = document.createElement('td');
				newInput_td4 = document.createElement('td');
				newInput_td5 = document.createElement('td');
				newInput_td6 = document.createElement('td');
				newInput_td7 = document.createElement('td');
				
				newInput2.setAttribute('id', 'kredit' + counter);
				newInput2.setAttribute('class', 'textInput');
				newInput2.setAttribute('name', 'kredit[]');
				newInput2.setAttribute('type', 'text');
				newInput2.setAttribute('onchange', "updateTotal_k('kredit[]')");
				
				/*newInput6.setAttribute('type','button');
				newInput6.setAttribute('onclick',"removeInputElmById(" + cancel_b + ")");
				newInput6.setAttribute('value','Remove');
				newInput6.setAttribute('name','btn_batal[]');*/
				newInput6.setAttribute('type','hidden');
				newInput6.setAttribute('onclick',"removeInputElmById(" + cancel_b + ")");
				newInput6.setAttribute('value','Remove');
				newInput6.setAttribute('name','btn_batal[]');
				
				newInput_anggaran.setAttribute('class', 'textInput');
				newInput_anggaran.setAttribute('name', 'anggaran_uang[]');
				newInput_anggaran.setAttribute('type', 'text');
				newInput_anggaran.setAttribute('id', 'anggaran_uang' + counter);
				newInput_anggaran.setAttribute('readonly', 'true');
				
				newInput_parent.setAttribute('class', 'textInput');
				newInput_parent.setAttribute('name', 'parent[]');
				newInput_parent.setAttribute('type', 'hidden');
				newInput_parent.setAttribute('id', 'parent' + counter);
				newInput_parent.setAttribute('readonly', 'true');
				
				newInput_idanggaran.setAttribute('class', 'textInput');
				newInput_idanggaran.setAttribute('name', 'id_anggaran[]');
				newInput_idanggaran.setAttribute('type', 'hidden');
				newInput_idanggaran.setAttribute('id', 'id_anggaran' + counter);
				newInput_idanggaran.setAttribute('readonly', 'true');
				
				newInput.setAttribute('class', 'textInput');
				newInput.setAttribute('name', 'debet[]');
				newInput.setAttribute('type', 'text');
				newInput.setAttribute('onchange', "updateTotal_d('debet[]')");
				
				newInput3.setAttribute('href', "<?=base_url().'index.php/penerimaan_kas/show_akun/'?>"+ counter);
				newInput3.setAttribute('id', 'addAkun' + counter);
				newInput3.setAttribute('class', 'add_akun');
				newInput3.innerHTML="Add Akun";
				
				//newInput3.setAttribute('value', "Tambah Akun");
				
				newInput4.setAttribute('class', 'textInput');
				newInput4.setAttribute('name', 'akunid[]');
				newInput4.setAttribute('type', 'text');
				newInput4.setAttribute('id', 'akunid' + counter);
				
				newInput5.setAttribute('class', 'textInputLeft');
				newInput5.setAttribute('name', 'nakun[]');
				newInput5.setAttribute('type', 'text');
				newInput5.setAttribute('id', 'nakun' + counter);
				
				newInput_td.appendChild(newInput_anggaran);  //anggaran
				
				newInput_td2.appendChild(newInput);  //debet
				newInput_td7.appendChild(newInput6); //kredit
				newInput_td3.appendChild(newInput3); 
				newInput_td4.appendChild(newInput4);
				newInput_td5.appendChild(newInput5);
				newInput_td6.appendChild(newInput2);
				newInput_td6.appendChild(newInput_parent);
				newInput_td6.appendChild(newInput_idanggaran);
				
				
				newInput_tr.appendChild(newInput_td2);
				newInput_tr.appendChild(newInput_td3);
				newInput_tr.appendChild(newInput_td4);
				newInput_tr.appendChild(newInput_td5);
				//newInput_tr.appendChild(newInput_td);				
				newInput_tr.appendChild(newInput_td6);
				//pembelian==pemasukan==kas di debet
				cancel_b = cancel_b +1;
				if (val_radio=='pemasukan'){
					/*newInput_tr.appendChild(newInput_tdnull);*/
					newInput_tr.appendChild(newInput_td2);
					
					newInput_tr.appendChild(newInput_td6);
					inCon.appendChild(newInput_tr);
				}else if(val_radio=='pengeluaran'){
					newInput_tr.appendChild(newInput_td);
					newInput_tr.appendChild(newInput_tdnull);
					
					newInput_tr.appendChild(newInput_td6);
					inCon.appendChild(newInput_tr);
				}
				
				$("a.add_akun").fancybox({
					'width'         : 970,
					'max-height'    : 900,
					'autoDimensions': false,
					'autoScale'     : false,
					'transitionIn'  : 'elastic',
					'transitionOut' : 'elastic',
				});
			}else{
				alert('Isi Terlebih Dahulu Input Text yang di atas');
			}
		}
		
		function removeInputElm(){
			tagAll = document.getElementsByTagName("*");
			inCon = document.getElementById('inputList');
			var jumlah = 0;
			for (var i=0;i<tagAll.length;i++){
				if (tagAll[i].getAttribute("name")=='btn_batal[]') {jumlah++};
			}
			jumlah = Number(jumlah);
			newP = document.getElementsByTagName('tr');
			child=inCon.children[jumlah-1];
			inCon.removeChild(child);
		}
		
		function change_radio(){
			tagAll = document.getElementsByTagName("*");
			inCon = document.getElementById('inputList');
			var jumlah = 0;
				for (var i=0;i<tagAll.length;i++){
					if (tagAll[i].getAttribute("name")=='btn_batal[]') {
						jumlah++;
					}
				}
			jumlah = Number(jumlah);
				
			for (var j=0;j<jumlah;j++){
				child=inCon.children[0];
				inCon.removeChild(child);
			}
			
			var val_radio = $('input:radio[name=id_pilihan]:checked').val();
			reset_txt();

		}
		function removeInputElmById(numb){
			inCon = document.getElementById('inputList');
			newP = document.getElementsByTagName('tr');
			child=inCon.children[numb];
			inCon.removeChild(child);
			
			//replaceChild() 
		}
		
		function updateTotal_d(s){
			var allEls=document.getElementsByTagName("*");
			newTotal = 0;
				for(var i=0;i<allEls.length;i++)
				{
					if(allEls[i].getAttribute("name")!=s)continue;
					if(isNaN(allEls[i].value))continue;
					newTotal = newTotal + Number(allEls[i].value);
				}
			var f=document.getElementById("jumlah_pemasukan");
			f.value= newTotal;
			sum_total();	
		}
		
		function updateTotal_k(s){
			var allEls_k=document.getElementsByTagName("*");
			newTotal_k = 0;
				for(var i=0;i<allEls_k.length;i++)
				{
					if(allEls_k[i].getAttribute("name")!=s)continue;
					if(isNaN(allEls_k[i].value))continue;
					//newTotal_k+=new Number(allEls_k[i].value);
					newTotal_k = newTotal_k + Number(allEls_k[i].value);
				}	
				var f=document.getElementById("jumlah_pengeluaran");
				f.value= newTotal_k;
				sum_total();
		}
		
		function sum_total(){
			var e=document.getElementById("txt_balance");
			var f=document.getElementById("jumlah_pemasukan");
			var g = document.getElementById("jumlah_pengeluaran");
			
			e.value= f.value - g.value;
		}
		
		function klick_tanggal(){
			var tanggal = document.getElementById("tanggal");
			tanggal.focus();
		} 
		
		$(function(){
			$("#tanggal").datepicker({dateFormat: 'yy-mm-dd' });
		})	


</script>
   
	<?php 
		if(validation_errors())
		{
	?>
			<ul class="message error grid_12">
				<li><?=validation_errors()?></li>
				<li class="close-bt"></li>
			</ul>	
	<?php
		} 
	?>
<div id="page-heading"><h1>Penerimaan Kas Tambah Data</h1></div>
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
<tr>
	<th rowspan="3" class="sized"><img src="<?php echo base_url() ?>asset/admin/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
	<th class="topleft"></th>
	<td id="tbl-border-top">&nbsp;</td>
	<th class="topright"></th>
	<th rowspan="3" class="sized"><img src="<?php echo base_url() ?>asset/admin/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
</tr>
<tr>
	<td id="tbl-border-left"></td>
	<td>
	<!--  start content-table-inner -->
	<div id="content-table-inner">
	
		<div id="table-content">
	<?php
		$attributes = array('name' => 'penerimaan_kas', 'id' => 'penerimaan_kas', 'class'=>'block-content form');
		echo form_open('penerimaan_kas/view_posting_penerimaan_kas', $attributes);
	?>
	<table border="0" width="100%" cellpadding="0" cellspacing="0">
	<tbody>
	<tr valign="top">
		<td>
			<!--  start step-holder -->
			<div id="step-holder">
				<div class="step-no">1</div>
				<div class="step-light-left"><?php 
					echo anchor('penerimaan_kas/index', 'List Penerimaan Kas');
				?></div>
				<div class="step-light-right">&nbsp;</div>
				<div class="step-no-off">2</div>
				<div class="step-dark-left"><?php 
					echo anchor('penerimaan_kas/insert', 'Tambah Data');
				?></div>
				<div class="step-dark-right">&nbsp;</div>
				<div class="step-no-off">3</div>
				<div class="step-light-left"><?php if ($can_view == TRUE){
					echo anchor('penerimaan_kas/list_posting', 'Posting Penerimaan Kas');
				}?></div>
				<div class="step-light-round">&nbsp;</div>
									
				<div class="clear"></div>
			</div>
			<!--  end step-holder -->
		
			<!-- start id-form -->
			<table border="0" cellpadding="0" cellspacing="0"  id="id-form" width="100%">
				
				<tr>
					<th valign="top">General Jurnal ID : </th>
					<td><input type="text" name="glid" id="glid" value="<?=$glid?>" readonly="true" class="inp-form"></td>
					<td></td>
				</tr>
				<tr>
					<th valign="top">Tanggal Transaksi: </th>
					<td class="noheight">
						<input type="text" name="tanggal" id="tanggal" class="inp-form" value="<?=date('Y-m-d')?>">
						<img onclick="javascript:klick_tanggal()" src="<?=base_url()?>asset/admin/images/icons/fugue/calendar-month.png" width="16" height="16">
					
					</td>
					<td></td>
				</tr>
				<tr><th></th><td></td></tr>
				<tr><th></th><td></td></tr>
		<!-- end id-form  -->

					<tr>
						<th>
							<input name="addInputs" id="addInputs" type="button" value="[add row]" />
							<!--<input name="removeBtn" id="removeBtn" type="button" value="[remove row]"  />-->
	
						</th>
						
					</tr>

					<tr>
						<td colspan="4">			
						<table class="table" border="1" cellspacing="0" width="100%" id="transaction-table">
							<thead>
								<tr>
									<th class="table-header-repeat line-left minwidth-1">Pilih Akun</th>
									<th class="table-header-repeat line-left minwidth-1">Akun Id</th>
									<th class="table-header-repeat line-left minwidth-1"><a href="">Nama Akun</a></th>
									<!--<th class="table-header-repeat line-left minwidth-1"><a href="">Anggaran</a></th>-->
									<th class="table-header-repeat line-left minwidth-1"><a href="">Debet</a></th>
									<th class="table-header-repeat line-left minwidth-1"><a href="">Kredit</a></th>
								</tr>
							</thead>
							<tbody id="id="items">
									<tr align="center" border="1" class="alternate-row">
										<td>
											<a id="getakun0" href="<?=base_url().'index.php/penerimaan_kas/show_akun/0'?>">Add Akun</a>
										</td>
										<td><input class="textInput" type="text" name="akunid[]" id="akunid0" value=""></td>
										<td><input class="textInputLeft" type="text" name="nakun[]" id="nakun0" value=""></td>
										 <input class="textInput" type="hidden" name="anggaran_uang[]" id="anggaran_uang0" readonly="true"  value=""> 
										<input class="textInput" type="hidden" name="parent[]" id="parent0" readonly="true"  value="">
										<input class="textInput" type="hidden" name="id_anggaran[]" id="id_anggaran0" readonly="true"  value="">
										<td><input class="textInput" type="text" name="debet[]" id="debet0" onchange="updateTotal_d('debet[]')" value=""></td>
										<td><input class="textInput" type="text" name="kredit[]" id="kredit0" onchange="updateTotal_k('kredit[]')" value=""></td>
									</tr>
								<tbody id="inputList">
								</tbody>
								<tr align="center" class="alternate-row">
									<td></td> 
									<td></td>
									<td></td>
									<td><input type="text" name="jumlah_pemasukan" id="jumlah_pemasukan" value="" class="textInput" readonly="true"></td>
									<td><input type="text" name="jumlah_pengeluaran" id="jumlah_pengeluaran" value="" class="textInput" readonly="true"></td>
								</tr>
								
								<tr align="center" class="alternate-row">
									<td></td> 
									<td></td>
									<td></td>
									<td colspan="2"><input type="text" name="txt_balance" id="txt_balance" value="" class="textInput" readonly="true"></td>
								</tr>
								
							</tbody>
						</table>
						</td>
					</tr>			
					<tr>
						<td valign="top">
							<input type="submit" value="Simpan" class="form-submit" />
							<input type="reset" value="Batal" class="form-reset"  />
						</td>
					</tr>		
			</table>
		</td>					
	</tr>
	</tbody>							
	</table>
<div class="clear"></div>
</form>
</div></div>
<!--  end content-table-inner  -->
</td>
	<td id="tbl-border-right"></td>
</tr>
<tr>
	<th class="sized bottomleft"></th>
	<td id="tbl-border-bottom">&nbsp;</td>
	<th class="sized bottomright"></th>
</tr>
</table>